home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !preview / RCS / c / build next >
Encoding:
Text File  |  1990-07-26  |  21.0 KB  |  906 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    gtoal:1.2;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     91.03.02.13.58.56;  author gtoal;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     91.03.02.13.55.17;  author gtoal;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @Initial release
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @IAY's upgrade
  28. @
  29. text
  30. @/* build.c --- Build the data structure as presented from the dvi file by
  31.    dviread.  */
  32.  
  33. #include "d2rd.h"
  34. #include "bbc.h"
  35. #include "font.h"
  36. #include <string.h>
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <stdarg.h>
  40. #include "kernel.h"
  41. #include "visdelay.h"
  42. #include "template.h"
  43. #include "colourtran.h"
  44. #include "res.h"
  45. #include "flex.h"
  46.  
  47. /* The allocation units while reading a dvi file.  Maybe these could just be
  48.    very large numbers, since the appriopriate arrays are re-alloc'd to the
  49.    right size afterwards anyway, or maybe not...  */
  50.  
  51. #define RULE_BLOCKSIZE     10
  52. #define TEXT_BLOCKSIZE     100
  53. #define CHAR_BLOCKSIZE     200
  54.  
  55.  
  56. /* Set this variable to 1 to be blown away by gunge while loading a dvi file.  */
  57.  
  58. extern int debug;
  59.  
  60.  
  61. /* CURRENT_DVI_FILE points to the struct dvi_file of the file currently being read.  */
  62.  
  63. struct dvi_file *current_dvi_file;
  64.  
  65.  
  66. /* CURRENT_PAGE idem dito of the current page.  PAGE_PTR points to the
  67.    pointer which should point to this page, which it indeed will as soon as
  68.    this page is completely loaded.  */
  69.  
  70. static struct page **page_ptr, *current_page;
  71.  
  72.  
  73. /* Possible \magstep values (magstep0, magstephalf, magstep1, ..., magstep5)
  74.    in the order of the magnification submenu.  */
  75.  
  76. double tex_magstep[] = {1.000, 1.095, 1.200, 1.440, 1.728, 2.074, 2.488};
  77.  
  78.  
  79. /* The fonthandle while reading the dvi file, as set by the last call to
  80.    setfont.  */
  81.  
  82. int current_font_handle;
  83.  
  84.  
  85. static int current_page_number;
  86.  
  87. int draw_page = 1;
  88.  
  89. int page_area_size;
  90.  
  91. int loading_a_file;
  92.  
  93. int x_os_scale, y_os_scale;
  94.  
  95. int rule_index, char_index, text_index;
  96.  
  97. int max_rule_index, max_char_index, max_text_index;
  98.  
  99.  
  100.  
  101. struct
  102. {
  103.   char val[1024];
  104.   _kernel_swi_regs r;
  105. } old_font;
  106.  
  107.  
  108. /* This sets the Font$Path to my own fonts.  It saves the old Font$Prefix
  109.    properly, which can't be done by getenv () and setenv () in case the
  110.    variable is something like a macro.  Hence this _kernel_swi () stuff.  */
  111.  
  112. void
  113. set_font_path (void)
  114. {
  115.   char *new_font_path;
  116.  
  117.   old_font.r.r[0] = (int) "Font$Path";
  118.   old_font.r.r[1] = (int) &old_font.val[0];
  119.   old_font.r.r[2] = 1024;
  120.   old_font.r.r[3] = old_font.r.r[4] = 0;
  121.   _kernel_swi (0x23, &old_font.r, &old_font.r);
  122.  
  123.   new_font_path = getenv ("PreviewFonts$Path");
  124.   if (new_font_path == NULL)
  125.     tfatal ("PreviewFonts$Path is not defined!");
  126.  
  127.   _kernel_setenv ("Font$Path", new_font_path);
  128. }
  129.  
  130.  
  131. void
  132. reset_font_path (void)
  133. {
  134.   old_font.r.r[3] = 0;
  135.   _kernel_swi (0x24, &old_font.r, &old_font.r);
  136. }
  137.  
  138.  
  139. /* Set the default values of a window.  */
  140.  
  141. void
  142. default_display_values (struct display *w)
  143. {
  144.   w->hor_size = (int)(A4_WIDTH  * MILLIPOINTS);
  145.   w->ver_size = (int)(A4_HEIGHT * MILLIPOINTS);
  146.   w->hor_offset = 1 * MILLIPOINTS; /* one inch, in millipoints */
  147.   w->ver_offset = 1 * MILLIPOINTS; /* one inch, in millipoints */
  148.   w->magstep = 0; w->mag_tweak = 1.0;
  149.   w->zoom = 0;
  150. }
  151.  
  152.  
  153. void
  154. factors (struct display *w, double *x, double *y)
  155. {
  156.   *x = *y = tex_magstep[w->magstep] * w->mag_tweak;
  157. }
  158.  
  159.  
  160. void
  161. fill_sprite (struct display *w)
  162. {
  163.   struct dvi_file *f = w->file;
  164.   struct font_use *fu;
  165.   struct page *p = w->page;
  166.   struct text *t;
  167.   struct rule *l;
  168.   wimp_palettestr current_palette;
  169.   wimp_paletteword pal;
  170.   _kernel_swi_regs r;
  171.   int h, i, k, x, y, dvi_to_handle[256];
  172.   int things = 0, bpp = bbc_vduvar (bbc_Log2BPP);
  173.   double xs, ys;
  174.  
  175.   visdelay_begin ();
  176.   set_font_path ();
  177.  
  178.   for (i = 0; i < 256; i++)
  179.     dvi_to_handle[i] = 0;
  180.  
  181.   wimp_readpalette (¤t_palette);
  182.  
  183.   r.r[0] = 60 + 256;
  184.   r.r[1] = (int) w->area;
  185.   r.r[2] = (int) w->sid.s.name;
  186.   r.r[3] = 0;
  187.  
  188.   err = (os_error *) _kernel_swi (0x2e, &r, &r);
  189.   if (err)
  190.     tfatal ("Can't redirect output to sprite: %s\n", err->errmess);
  191.  
  192.   /* Output is now to the sprite.  */
  193.  
  194.   wimp_setpalette (¤t_palette);
  195.  
  196.   pal.word = -1; pal.bytes.gcol = 0;
  197.   colourtran_setGCOL (pal, 128, 0, &i);
  198.   bbc_clg ();
  199.  
  200.   factors (w, &xs, &ys);
  201.  
  202.   pal.word = -1;
  203.  
  204.   for (t = p->texts, i = 0; i < p->text_max; t++, i++)
  205.     {
  206.       /* If the dvi to handle translation results in 0, the font has not been
  207.          found yet.  Thus, find it at the appropriate size.  */
  208.  
  209.       if (t->font > 255)
  210.         tfatal ("fontno = %d\n", t->font);
  211.  
  212.       if (dvi_to_handle[t->font] == 0)
  213.         {
  214.           fu = f->fonts[t->font];
  215.           err = font_find (fu->name, (int) (fu->size * xs), (int) (fu->size * ys), 0, 0, &dvi_to_handle[t->font]);
  216.           if (err)
  217.             {
  218.               dvi_to_handle[t->font] = 0;
  219.               continue;
  220.             }
  221.         }
  222.  
  223.       font_setcolour (dvi_to_handle[t->font], 0, 1, bpp == 0 ? 0 : bpp == 1 ? 2 : bpp == 2 ? 6 : 14);
  224.       font_paint (&p->chars[t->text], 0, (int)(t->x * xs),
  225.          (int)((w->ver_size - w->ver_offset - t->y) * ys));
  226.       visdelay_percent ((100 * things++) / p->things);
  227.     }
  228.  
  229.   for (i = 0; i < 256; i++)
  230.     if (dvi_to_handle[i])
  231.       font_lose (dvi_to_handle[i]);
  232.  
  233.   pal.word = 0;
  234.   colourtran_setGCOL (pal, 0, 0, &i);
  235.  
  236.   for (l = p->rules, i = 0; i < p->rule_max; l++, i++)
  237.     {
  238.       visdelay_percent ((100 * things++) / p->things);
  239.       font_converttoos ((int)(l->x * xs),
  240.          (int)((w->ver_size - w->ver_offset - l->y) * ys), &x, &y);
  241.       font_converttoos ((int) (l->w * xs), (int) (l->h * ys), &k, &h);
  242.       bbc_rectanglefill (x, y, k, h);
  243.     }
  244.  
  245.   /* Re-redirect output to the screen again.  */
  246.  
  247.   _kernel_swi (0x2e, &r, &r);
  248.  
  249.   reset_font_path ();
  250.  
  251.   visdelay_percent (-1);
  252.   visdelay_end ();
  253. } /* fill_sprite */
  254.  
  255.  
  256.  
  257. /********
  258.   */
  259.  
  260. int
  261. define_sprite (struct display *w)
  262. {
  263.   char *sprite_name = xmalloc (12);
  264.   double xfac, yfac;
  265.   int xpix, ypix;
  266.   int size;
  267.  
  268.   factors (w, &xfac, &yfac);
  269.  
  270.   font_converttoos( (int)((w->hor_size - w->hor_offset) * xfac),
  271.                     (int)((w->ver_size - w->ver_offset) * yfac),
  272.                     &xpix, &ypix);
  273.  
  274.   xpix /= x_os_scale; xpix = (xpix+31) & ~31;
  275.   ypix /= y_os_scale;
  276.  
  277.   size = (int) (1024 +
  278.      (xpix * ypix * (1 << bbc_vduvar (bbc_Log2BPP))) / 8.0);
  279.  
  280. #ifdef USE_FLEX
  281.   if (flex_alloc ((flex_ptr) &w->area, size) == 0)
  282.     tfatal ("failed to allocate space for aprite area");
  283. #else
  284.   w->area = xmalloc (size);
  285. #endif
  286.  
  287.   sprite_area_initialise (w->area, size);
  288.  
  289.   sprintf (sprite_name, "page");
  290.   w->sid.tag =0;
  291.   w->sid.s.name = sprite_name;
  292.  
  293.   err = sprite_create (w->area, sprite_name, TRUE,
  294.                        xpix, ypix, vdu_mode);
  295.   if (err)
  296.     tfatal ("Can't create sprite: %s\n", err->errmess);
  297.  
  298.   return (0);
  299. } /* define_sprite */
  300.  
  301.  
  302.  
  303. void
  304. adjust_window_size (struct display *w)
  305. {
  306.   wimp_redrawstr r;
  307.   wimp_wstate s;
  308.   double xfac, yfac;
  309.  
  310.   factors (w, &xfac, &yfac);
  311.  
  312.   r.w = w->w_handle;
  313.   r.box.x0 = 0;
  314.   r.box.y0 = 0;
  315.   font_converttoos((int)(w->hor_size*xfac), (int)(w->ver_size*yfac), &r.box.x1, &r.box.y1);
  316.   wimpt_noerr (wimp_set_extent (&r));
  317.  
  318.   r.w = w->w_handle;
  319.   r.box.x0 = 0;
  320.   r.box.y0 = 0;
  321.   r.box.x1 = 1 << 30;
  322.   r.box.y1 = 1 << 30;
  323.   wimpt_noerr (wimp_force_redraw (&r));
  324.  
  325.   wimp_get_wind_state (w->w_handle, &s);
  326.   wimp_open_wind (&s.o);
  327. } /* adjust_window_size */
  328.  
  329.  
  330.  
  331. void
  332. set_window_title (struct display *w)
  333. {
  334.   wimp_wstate ws;
  335.  
  336.   sprintf (w->w_title, "%s %d%s", w->file->f_name, w->page->dvi_page, w->file->complete ? "" : " *");
  337.   wimpt_noerr (wimp_get_wind_state (w->w_handle, &ws));
  338.   ws.o.box.x1 -= 4;
  339.   wimpt_noerr (wimp_open_wind (&ws.o));
  340.   ws.o.box.x1 += 4;
  341.   wimpt_noerr (wimp_open_wind (&ws.o));
  342. }
  343.  
  344.  
  345.  
  346. void
  347. build_a_window (struct dvi_file *df, struct page *p)
  348. {
  349.   struct display *w;
  350.   wimp_wind *wind;
  351.   wimp_openstr wop;
  352.   double xfac, yfac;
  353.  
  354.   w = xcalloc (1, sizeof (struct display));
  355.   w->file = df;
  356.   w->page = p;
  357.  
  358.   w->w_title = xmalloc (300);
  359.   sprintf (w->w_title, "%s", df->f_name);
  360.  
  361.   default_display_values (w);
  362.   define_sprite (w);  
  363.   fill_sprite (w);
  364.  
  365.   wind = template_syshandle ("yesyes");
  366.   factors (w, &xfac, &yfac);
  367.  
  368.   wind->ex.x0 = 0;
  369.   wind->ex.y0 = 0;
  370.   font_converttoos((int)(w->hor_size*xfac), (int)(w->ver_size*yfac),
  371.       &wind->ex.x1, &wind->ex.y1);
  372.   wind->titleflags |= wimp_ITEXT | wimp_INDIRECT ;
  373.   wind->titleflags &= ~(wimp_ISPRITE);
  374.   wind->title.indirecttext.buffer = w->w_title;
  375.   wind->title.indirecttext.validstring = NULL;
  376.   wind->title.indirecttext.bufflen = 300;
  377.  
  378.   wimpt_noerr (wimp_create_wind (wind, &w->w_handle));
  379.  
  380.   /*
  381.   ** Having created the window, we now open it.
  382.   ** Initially, the part of the work area we want visible
  383.   ** is the middle of the topmost part.  We can skip part
  384.   ** of the top margin, too, as it won't have anything in it.
  385.   */
  386.   wop.w = w->w_handle;
  387.   wop.box = wind->box;
  388.   font_converttoos( 0, (int)((w->ver_size-(w->ver_offset/2)) * yfac),
  389.                     &wop.x, &wop.y );
  390.   wop.x = (wind->ex.x1-(wop.box.x1-wop.box.x0))/2;
  391.   if (wop.x<0) wop.x = 0; /* in case of smaller work area than window */
  392.   wop.behind = -1;
  393.   wimp_open_wind (&wop);
  394.  
  395.   set_window_title (w);
  396.  
  397.   w->next = windows;
  398.   windows = w;
  399. } /* build_a_window */
  400.  
  401.  
  402.  
  403. /**********
  404.    Read a dvifile and build a dvi_file structure.  Return 0 if no error
  405.    occured, +1 if an error occured and the user has already been notified, -1
  406.    otherwise.  */
  407.  
  408. int
  409. read_a_file (char *name)
  410. {
  411.   char *dviread_argv[2], *xname, *real_name;
  412.   struct dvi_file *df;
  413.   struct display *w;
  414.   FILE *f;
  415.  
  416.   if (loading_a_file)
  417.     {
  418.       fatal ("Already loading a file.  Please wait.");
  419.       return (1);
  420.     }
  421.  
  422.   /* If NAME is a directory, try looking for a file called dvi in there.  If
  423.      this exists, correct NAME. */
  424.  
  425.   xname = malloc (5 + strlen (name));
  426.   sprintf (xname, "%s.dvi", name);
  427.   f = fopen (xname, "rb");
  428.   fclose (f);
  429.   real_name = (f == NULL ? name : xname);
  430.  
  431.   /* If this file is already loaded bring his window to the front so the user
  432.      will see this as well (and spot the `mistake').  */
  433.  
  434.   for (w = windows; w; w = w->next)
  435.     if (strcmp (w->file->f_name, real_name) == 0)
  436.       {
  437.         wimp_wstate r;
  438.  
  439.         wimpt_complain (wimp_get_wind_state (w->w_handle, &r));
  440.         r.o.behind = -1;
  441.         wimpt_complain (wimp_open_wind (&r.o));
  442.         free (xname);
  443.         return (0);
  444.       }
  445.  
  446.   /* Alles klar Herr Commissar.  */
  447.  
  448.   df = calloc (1, sizeof (struct dvi_file));
  449.   if (df == NULL)
  450.     {
  451.       fatal ("Out of memory, sorry.\n");
  452.       return (1);
  453.     }
  454.  
  455.   df->f_name = malloc (1 + strlen (real_name));
  456.   if (df->f_name == NULL)
  457.     {
  458.       fatal ("Out of memory, sorry.\n");
  459.       return (1);
  460.     }
  461.  
  462.   strcpy (df->f_name, real_name);
  463.  
  464.   dviread_argv[0] = "6 * 9 == 42";
  465.   dviread_argv[1] = real_name;
  466.   page_ptr = &df->pages;
  467.   current_page_number = 0;
  468.   current_dvi_file = df;
  469.   loading_a_file = TRUE;
  470.   df->complete = FALSE;
  471.  
  472.   /* Switch on hourglass and start reading the dvi file. The accompanying
  473.      visdelay_end () is in DRAW_endpage, where the hourglass is switched off
  474.      after having loaded the first page.  */
  475.  
  476.   visdelay_begin ();
  477.   dviread_main (2, dviread_argv);
  478.  
  479.   df->complete = TRUE;
  480.   df->next = dvi_files;
  481.   dvi_files = df;
  482.  
  483.   /* Windows _must_ point to the newly loaded file's window.  */
  484.  
  485.   for (w = windows; w; w = w->next)
  486.     if (w->file == df)
  487.       set_window_title (w);
  488.  
  489.   loading_a_file = FALSE;
  490.   free (xname);
  491.   return (0);
  492. } /* read_a_file */
  493.  
  494.  
  495.  
  496.  
  497. /* Delete the display_window with window handle H from the list of window
  498.    display's.  If no such entry in the list can be found, just return
  499.    without further action.  */
  500.  
  501. void
  502. delete_display (wimp_w h)
  503. {
  504.   struct display **w, *t, *t2;
  505.   struct dvi_file *f, **pf;
  506.   int i;
  507.   struct page *p, *q;
  508.  
  509.   for (w = &windows; *w; w = &(*w)->next)
  510.     if ((*w)->w_handle == h)
  511.       break;
  512.  
  513.   if (*w)
  514.     {
  515.       t = *w;
  516.       *w = t->next;
  517.       for (t2 = windows; t2; t2 = t2->next)
  518.         if (t2->file == t->file)
  519.           break;
  520.  
  521.       /* If T2 is NULL, this is the last display onto that dvi file, so the
  522.          dvi file structure can be deleted as well.  */
  523.  
  524.       if (t2 == NULL)
  525.         for (pf = &dvi_files; *pf; pf = &(*pf)->next)
  526.           if (*pf == t->file)
  527.             {
  528.               f = *pf;
  529.               *pf = f->next;
  530.               for (i = 0; i < 256; i++)
  531.                 if (f->fonts[i])
  532.                   free (f->fonts[i]);
  533.               for (p = f->pages; p; p = q)
  534.                 {
  535. #ifdef USE_FLEX
  536.                   flex_free ((flex_ptr) &p->texts);
  537.                   flex_free ((flex_ptr) &p->rules);
  538.                   flex_free ((flex_ptr) &p->chars);
  539. #else
  540.                   free (p->texts);
  541.                   free (p->rules);
  542.                   free (p->chars);
  543. #endif
  544.                   q = p->next;
  545.                   free (p);
  546.                 }
  547.               break;
  548.             }
  549.  
  550. #ifdef USE_FLEX
  551.       flex_free ((flex_ptr) &t->area);
  552. #else
  553.       free (t->area);
  554. #endif
  555.       free (t);
  556.     }
  557. }
  558.  
  559. /******************************************
  560.  
  561.              DRAW_  routines
  562.  
  563.  ******************************************/
  564.  
  565.  
  566.  
  567. void
  568. DRAW_startpage(void)
  569. {
  570.   struct page *p = xcalloc (1, sizeof (struct page));
  571.  
  572.   p->dvi_page = ++current_page_number;
  573.   p->complete = FALSE;
  574.  
  575.   text_index = 0;
  576.   max_text_index = TEXT_BLOCKSIZE;
  577.  
  578. #ifdef USE_FLEX
  579.   if (flex_alloc ((flex_ptr) &p->texts, TEXT_BLOCKSIZE * sizeof (struct text)) == 0)
  580.     tfatal ("failed to allocate room for text");
  581. #else
  582.   p->texts = xmalloc (TEXT_BLOCKSIZE * sizeof (struct text));
  583. #endif
  584.  
  585.   rule_index = 0;
  586.   max_rule_index = RULE_BLOCKSIZE;
  587.  
  588. #ifdef USE_FLEX
  589.   if (flex_alloc ((flex_ptr) &p->rules, RULE_BLOCKSIZE * sizeof (struct rule)) == 0)
  590.     tfatal ("failed to allocate room for chars");
  591. #else
  592.   p->rules = xmalloc (RULE_BLOCKSIZE * sizeof (struct rule));
  593. #endif
  594.  
  595.   char_index = 0;
  596.   max_char_index = CHAR_BLOCKSIZE;
  597.  
  598. #ifdef USE_FLEX
  599.   if (flex_alloc ((flex_ptr) &p->chars, CHAR_BLOCKSIZE) == 0)
  600.     tfatal ("failed to allocated room for rules");
  601. #else
  602.   p->chars = xmalloc (CHAR_BLOCKSIZE);
  603. #endif
  604.  
  605.   *page_ptr = p;
  606.   page_ptr = &p->next;
  607.   p->things = 0;
  608.   current_page = p;
  609. }
  610.  
  611.  
  612.  
  613. void
  614. DRAW_text(int xl, int yb, int xr, int yt, char *text)
  615. {
  616.   struct text *t;
  617.   int i, len = 1 + strlen (text);
  618.  
  619.   yt = yt, xr = xr;   /* Indeed, to make cc shut up.  */
  620.  
  621.   /* If LEN == 1, a `zero string' was passed.  This could only come from
  622.      DRAW_char, so we got passed a one-character string with the character 0
  623.      in it.  */
  624.  
  625.   if (len == 1)
  626.     len = 2;
  627.  
  628.   if (char_index + len >= max_char_index)
  629.     {
  630.       max_char_index += CHAR_BLOCKSIZE;
  631. #ifdef USE_FLEX
  632.       if (flex_extend ((flex_ptr) ¤t_page->chars, max_char_index) == 0)
  633.         tfatal ("OUT OF MEMORY");
  634. #else
  635.       current_page->chars = xrealloc (current_page->chars, max_char_index);
  636. #endif
  637.     }
  638.  
  639.   for (i = 1; i < len; i++)
  640.     text[i - 1] |= 128;
  641.   strcpy (¤t_page->chars[char_index], text);
  642.  
  643.   if (text_index == max_text_index)
  644.     {
  645.       max_text_index += TEXT_BLOCKSIZE;
  646. #ifdef USE_FLEX
  647.       if (flex_extend ((flex_ptr) ¤t_page->texts, max_text_index * sizeof (struct text)) == 0)
  648.         tfatal ("OUT OF MEMORY");
  649. #else
  650.       current_page->texts = xrealloc (current_page->texts, max_text_index * sizeof (struct text));
  651. #endif
  652.     }
  653.  
  654.   t = ¤t_page->texts[text_index];
  655.   t->font = current_font_handle;
  656.   t->text = char_index;
  657.   t->x = xl;
  658.   t->y = yb;
  659.   t->rx = xr;
  660.   t->ty = yt;
  661.  
  662.   current_page->things++;
  663.   char_index += len;
  664.   text_index++;
  665.  
  666.   if (current_dvi_file->pages->complete && current_page->things % 66 == 0)
  667.     do_a_poll ();
  668. }
  669.  
  670.  
  671. /**********
  672.    Write one character.  This might be a special character (unprintable ASCII
  673.    code) hence this routine, which tweaks the character and just calls
  674.    DRAW_text to print it.  */
  675.  
  676. void
  677. DRAW_char(int xl, int yb, char c)
  678. {
  679.   char a[2];
  680.  
  681.   a[0] = c; a[1] = 0;
  682.   DRAW_text (xl, yb, xl + 100, yb, a);
  683.  
  684.   if (debug)
  685.     fprintf(stderr, "Draw_char(xl = %d, yb = %d, char = %d)\n", xl, yb, c);
  686. }
  687.  
  688.  
  689. /**********
  690.    Draw a rule at the specified position (X, Y) and of the specified width DX
  691.    and height DY.  */
  692.  
  693. void
  694. DRAW_rule(int x, int y, int dy, int dx)
  695. {
  696.   struct rule *r;
  697.  
  698.   if (rule_index == max_rule_index)
  699.     {
  700.       max_rule_index += RULE_BLOCKSIZE;
  701. #ifdef USE_FLEX
  702.       if (flex_extend ((flex_ptr) ¤t_page->rules, max_rule_index * sizeof (struct rule)) == 0)
  703.         tfatal ("barf r1");
  704. #else
  705.      current_page->rules = xrealloc (current_page->rules, max_rule_index * sizeof (struct rule));
  706. #endif
  707.     }
  708.  
  709.   r = ¤t_page->rules[rule_index];
  710.  
  711.   r->x = x;
  712.   r->y = y;
  713.   r->w = dx;
  714.   r->h = dy;
  715.  
  716.   current_page->things++;
  717.   rule_index++;
  718.  
  719. #if 0
  720. printf ("%d %d %d %p %p %p\n", char_index, text_index, rule_index, current_page->chars, current_page->texts, current_page->rules);
  721. #endif
  722.  
  723.   if (debug)
  724.     fprintf(stderr, "Draw_rule(xl = %d, yb = %d, dx = %d, dy = %d)\n", x, y, dx, dy);
  725. }
  726.  
  727.  
  728. /**********
  729.    Select a new current font.  */
  730.  
  731. void
  732. DRAW_selfont(int fno)
  733. {
  734.   current_font_handle = fno;
  735.   if (debug) fprintf(stderr, "Draw_selfont (fno = %d)\n", fno);
  736. }
  737.  
  738.  
  739. /**********
  740.    Define a font, named FNAME, of size SIZE, and to be identified as FNO.
  741.    SIZE is in 16th of a point.  Also check if the font actually exists, so an
  742.    error can be issued, because if the font appears not to be present while
  743.    redrawing the sprite we can't issue an error message.  */
  744.  
  745. void
  746. DRAW_deffont(int fno, char *fname, int size, int mag)
  747. {
  748.   char *s;
  749.   struct font_use *f;
  750.   int fh;
  751.  
  752.   s = xmalloc (1 + strlen (fname));
  753.   sprintf (s, "%s", fname);
  754.  
  755.   set_font_path ();
  756.   err = font_find (s, size * mag / 1000, size * mag / 1000, 0, 0, &fh);
  757.   if (err)
  758.     {
  759.       fatal ("Cannot find font `%s': %s\n", fname, err->errmess);
  760.       reset_font_path ();
  761.       do_a_poll ();
  762.     }
  763.   else
  764.     {
  765.       font_lose (fh);
  766.       reset_font_path ();
  767.     }
  768.  
  769.   f = xcalloc (1, sizeof (struct font_use));
  770.   f->name = s;
  771.   f->size = size * mag / 1000;
  772.   current_dvi_file->fonts[fno] = f;
  773.  
  774.   reset_font_path ();
  775.  
  776.   if (debug)
  777.     fprintf(stderr, "Draw_deffont(no = %d, name = \"%s\", size = %d/16)\n", fno, fname, size);
  778. }
  779.  
  780.  
  781. /********
  782.    Mark the end of a page.  MAXH and MAXV are the observed limits for this
  783.    page; COUNT points to an array of TeX page counters.  */
  784.  
  785. void
  786. DRAW_endpage(int maxh, int maxv, int *count)
  787. {
  788.   memcpy (current_page->tex_pages, count, 10 * sizeof (int));
  789.   current_page->complete = TRUE;
  790.   current_dvi_file->height = maxv;
  791.   current_dvi_file->width = maxh;
  792.  
  793. #ifdef USE_FLEX
  794.   if (flex_extend ((flex_ptr) ¤t_page->texts, text_index * sizeof (struct text)) == 0)
  795.     tfatal ("barf e1");
  796.   if (flex_extend ((flex_ptr) ¤t_page->chars, char_index) == 0)
  797.     tfatal ("barf e2");
  798.   if (flex_extend ((flex_ptr) ¤t_page->rules, rule_index * sizeof (struct rule)) == 0)
  799.     tfatal ("barf e1");
  800. #else
  801.   current_page->texts = xrealloc (current_page->texts, text_index * sizeof (struct text));
  802.   current_page->chars = xrealloc (current_page->chars, char_index);
  803.   current_page->rules = xrealloc (current_page->rules, rule_index * sizeof (struct rule));
  804. #endif
  805.  
  806.   current_page->text_max = text_index;
  807.   current_page->rule_max = rule_index;
  808.   current_page->char_max = char_index;
  809.  
  810.   if (debug)
  811.     fprintf(stderr, "Draw_endpage(%d, %d, %d)\n", maxh, maxv, count[0]);
  812.  
  813.   if (current_page_number == 1)
  814.     {
  815.       build_a_window (current_dvi_file, current_dvi_file->pages);
  816.       visdelay_end ();
  817.     }
  818. }
  819.  
  820. /* EOF */
  821. @
  822.  
  823.  
  824. 1.1
  825. log
  826. @Initial revision
  827. @
  828. text
  829. @d7 4
  830. a10 4
  831. #include "string.h"
  832. #include "stdlib.h"
  833. #include "stdio.h"
  834. #include "stdarg.h"
  835. d47 1
  836. a47 1
  837. int tex_magstep[] = {1000, 1095, 1200, 1440, 1728, 2074, 2488};
  838. a86 1
  839.   int l;
  840. d115 5
  841. a119 6
  842.   w->hor_size = XA4_AT_95DPI;
  843.   w->ver_size = YA4_AT_95DPI;
  844.   w->hor_offset = ONE_OS_INCH;
  845.   w->ver_offset = ONE_OS_INCH;
  846.   w->dpi = 95;
  847.   w->magstep = 0;
  848. d125 1
  849. a125 1
  850. factors (struct display *w, int *x, int *y)
  851. d127 1
  852. a127 2
  853.   *x = tex_magstep[w->magstep] * w->dpi;
  854.   *y = tex_magstep[w->magstep] * w->dpi;
  855. d171 1
  856. a171 1
  857.   factors (w, &x, &y);
  858. a172 3
  859.   xs = (double) x / (double) MAGNIFICATION_DIVISOR;
  860.   ys = (double) y / (double) MAGNIFICATION_DIVISOR;
  861.  
  862. d195 2
  863. a196 1
  864.       font_paint (&p->chars[t->text], 0, (int) (t->x * xs), (int) ((((w->ver_size - w->ver_offset) * 72000.0 / 95.0) - t->y) * ys));
  865. d210 2
  866. a211 1
  867.       font_converttoos ((int) (l->x * xs), (int) ((((w->ver_size - w->ver_offset) * 72000.0) / 95.0 - l->y) * ys), &x, &y);
  868. d235 2
  869. a236 1
  870.   int xfac, yfac;
  871. d240 7
  872. a246 6
  873.   size = (int) (1024 + ((double) ((w->hor_size - w->hor_offset + 31) & ~31)
  874.                         * (double) xfac / (double) MAGNIFICATION_DIVISOR
  875.                         * (double) yfac / (double) MAGNIFICATION_DIVISOR
  876.                         * (double) (w->ver_size - w->ver_offset)
  877.                         * (1 << bbc_vduvar (bbc_Log2BPP))) / 7.9);
  878.                                             /* tweak tweak  ^^^ */
  879. d248 3
  880. d265 1
  881. a265 2
  882.                        (int) ((w->hor_size - w->hor_offset) * xfac / MAGNIFICATION_DIVISOR),
  883.                        (int) ((w->ver_size - w->ver_offset) * yfac / MAGNIFICATION_DIVISOR), vdu_mode);
  884. d279 1
  885. a279 1
  886.   int xfac, yfac;
  887. d286 1
  888. a286 2
  889.   r.box.x1 = (int) (w->hor_size * xfac / MAGNIFICATION_DIVISOR * x_os_scale);
  890.   r.box.y1 = (int) (w->ver_size * yfac / MAGNIFICATION_DIVISOR * 2);
  891. d323 1
  892. a323 1
  893.   int xfac, yfac;
  894. d341 2
  895. a342 2
  896.   wind->ex.x1 = (int) (w->hor_size * xfac / MAGNIFICATION_DIVISOR * x_os_scale);
  897.   wind->ex.y1 = (int) (w->ver_size * yfac / MAGNIFICATION_DIVISOR * 2);
  898. d351 6
  899. d359 4
  900. a362 2
  901.   wop.x = 0;
  902.   wop.y = (int) (w->ver_size * y_os_scale * yfac / MAGNIFICATION_DIVISOR);
  903. a588 1
  904.   char *s, *s2;
  905. @
  906.